package demo

import java.text.SimpleDateFormat

class PoorstatisticsController {
    def dynamicQueryService

    def poorstatistics() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime() - 2))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date().clearTime() - 1))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def tableHeadList = []
        def poorstatistics = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        if (params.EXPORT_CONTENT_NAME == 'Excel') {
            params.SYS_QUERY_NAME = 'poorstatistics'
            poorstatistics = dynamicQueryService.queryForList(params)
            if (poorstatistics.size() > 0) {
                tableHeadList = poorstatistics[0].keySet()
            }
        }
        params.SYS_QUERY_NAME = 'typeList'
        def typeList = dynamicQueryService.queryForList(params)
        [pageSize      : pageSize,
         totalCount    : totalCount,
         pageSizeList  : pageSizeList,
         tableHeadList : tableHeadList,
         poorstatistics: poorstatistics,
         startTime     : params.startTime ?: '',
         endTime       : params.endTime ?: '',
         name          : params.name,
         typeList      : typeList,

        ]
    }

    def poorstatistics1() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime() - 2))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date().clearTime() - 1))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def tableHeadList = []
        def poorstatistics1 = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        params.SYS_QUERY_NAME = 'poorstatistics1'
        poorstatistics1 = dynamicQueryService.queryForList(params)
        if (poorstatistics1.size() > 0) {
            tableHeadList = poorstatistics1[0].keySet()

        }

        [pageSize       : pageSize,
         totalCount     : totalCount,
         pageSizeList   : pageSizeList,
         tableHeadList  : tableHeadList,
         poorstatistics1: poorstatistics1,
         startTime      : params.startTime ?: '',
         endTime        : params.endTime ?: '',
        ]
    }

}
